package elion.com.theElion.activityMain;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import java.util.List;

import elion.com.elion.R;
import elion.com.theElion.util.MyFragmentPagerAdapter;

/**
 * Created by xiaon on 2017/6/6.
 */

public abstract class MyTabActivity extends AppCompatActivity {

    protected ViewPager viewPager;
    protected TabLayout tabLayout;

    protected MyFragmentPagerAdapter adapter;

    protected String[] titles;
    protected List<Fragment> fragments;
    protected View view;


    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_tab);

        //TabLayout

        findView();
        initData();
        setting();
    }


    private void initData() {

        this.fragments = setFragment();
        this.titles = setTitles();
        adapter = new MyFragmentPagerAdapter(getSupportFragmentManager(),
                this);
        adapter.setContentList(fragments);
        adapter.setContentTitles(titles);
        viewPager.setOffscreenPageLimit(4);
        viewPager.setAdapter(adapter);
        tabLayout.setupWithViewPager(viewPager);
        tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
        tabLayout.setTabMode(TabLayout.MODE_FIXED);
        tabLayoutSetting();

    }

    public void findView() {
        tabLayout = (TabLayout) findViewById(R.id.tl_land_data);
        viewPager = (ViewPager) findViewById(R.id.viewPager);
    }

    public abstract List<Fragment> setFragment();

    public abstract String[] setTitles();

    public abstract void setting();

    public abstract void tabLayoutSetting();

}
